package com.itheima.controller;

import com.itheima.domain.UmsMenu;
import com.itheima.manager.UmsMenuManager;
import com.itheima.util.R;
import com.itheima.vo.UmsMenuVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author ZhuHongKai
 * @version 1.0
 * @ClassName UmsMenuController
 * @date 2022/11/12 22:19
 */
@RestController
public class UmsMenuController {

    @Autowired
    UmsMenuManager umsMenuManager;

    /**
     * 树形结构返回所有菜单列表
     * @return
     */
    @RequestMapping(value = "/menu/treeList",method = RequestMethod.GET)
    public R getTreeList(){
        return umsMenuManager.getTreeList();
    }

    /**
     * 分页查询后台菜单
     * @param parentId
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/menu/list/{parentId}")
    public R getList(
        @PathVariable Long parentId,
        @RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum,
        @RequestParam(value = "pageSize",defaultValue = "10") Integer pageSize
    ){
        return umsMenuManager.getList(parentId,pageNum,pageSize);
    }

    /**
     * 添加后台菜单
     * @param umsMenu
     * @return
     */
    @PostMapping("/menu/create")
    public R createBackgroundMenu(@RequestBody UmsMenu umsMenu){
        return umsMenuManager.createBackgroundMenu(umsMenu);
    }

    /**
     * 根据ID获取菜单详情
     * @param id
     * @return
     */
    @GetMapping("/menu/{id}")
    public R getMenuDetails(@PathVariable Long id){
        return umsMenuManager.getMenuDetails(id);
    }

    /**
     * 修改后台菜单
     * @param id
     * @param umsMenu
     * @return
     */
    @PostMapping("/menu/update/{id}")
    public R updateMenu(@PathVariable Long id,@RequestBody UmsMenu umsMenu){
        return umsMenuManager.updateMenu(id,umsMenu);
    }

    /**
     * 修改菜单显示状态
     * @param id
     * @param hidden
     * @return
     */
    @PostMapping("/menu/updateHidden/{id}")
    public R updateHidden(@PathVariable Long id,Integer hidden){
        return umsMenuManager.updateHidden(id,hidden);
    }

    /**
     * 根据ID删除后台菜单
     * @param id
     * @return
     */
    @PostMapping("/menu/delete/{id}")
    public R delete(@PathVariable Long id){
        return umsMenuManager.delete(id);
    }
}
